import PlayerModel from 'server/model/playerModel';
import ItemModel from 'server/model/itemModel';
import FightAttri from 'server/model/fightAttri';
import playerStorage from 'js/core/playerStorage';
import packageHandle from 'server/handle/packageHandle';
import listPackageHandle from 'server/handle/listPackageHandle';
import partnerHandle from 'server/handle/partnerHandle';

import {
    totalConfig,
    propName
} from 'server/config/templateConfig';

class PlayerHandle {
    static getInstance() {
        if (!PlayerHandle.instance) {
            PlayerHandle.instance = new PlayerHandle();
        }
        return PlayerHandle.instance;
    }

    //初始化角色信息
    initPlayer(player) {
        player.battleTeams = partnerHandle.getBattleTeam(player.battleTeams);
        player.partnerTeams = partnerHandle.getPartnerTeam(player.partnerTeams);
        player.bag = packageHandle.initPackag(player.bag);
        player.warehouse = packageHandle.initPackag(player.warehouse);
        player.riskBag = listPackageHandle.initPackag(player.riskBag);
    }

    calcPlayer(player) {
        player.battleTeams = partnerHandle.initBattleTeam(player.battleTeams);
        player.partnerTeams = partnerHandle.initPartnerTeam(player.partnerTeams);
        player.bag = packageHandle.initPackag(player.bag);
        player.warehouse = packageHandle.initPackag(player.warehouse);
        player.riskBag = listPackageHandle.initPackag(player.riskBag);
    }

    copyPlayer(player) {
        player.battleTeams = partnerHandle.getBattleTeam(player.battleTeams);
        player.partnerTeams = partnerHandle.getPartnerTeam(player.partnerTeams);
        player.bag = packageHandle.initPackag(player.bag);
        player.warehouse = packageHandle.initPackag(player.warehouse);
        player.riskBag = listPackageHandle.initPackag(player.riskBag);
    }

    createPlayer() {
        let player = new PlayerModel();
        playerStorage.save(player);
        this.initPlayer(player);
        return player;
    }

    getExp(player, exp) {
        player.basicInfo.exp += exp;
        let lvlexp = playerConfig.lvlexp[player.basicInfo.lvl - 1];
        if (player.basicInfo.exp >= lvlexp) {
            player.basicInfo.lvl += 1;
            this.calcAttri(player)
        }
    }
}

let playerHandle = PlayerHandle.getInstance();
export default playerHandle;